#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=100010;
ll n,m,t;
struct node
{
	ll l,r;
	ll sum,add,mu;
}tr[N*4];
ll a[N];

void pushup(ll u)
{
	tr[u].sum=(tr[u<<1].sum+tr[u<<1|1].sum)%t;
}
void pushdown(ll u)
{
	auto &root=tr[u],&left=tr[u<<1],&right=tr[u<<1|1];
	if(root.add || root.mu!=1)
	{
		left.add=(root.add+left.add*root.mu)%t;
	    right.add=(root.add+right.add*root.mu)%t;
		left.mu=(left.mu*root.mu)%t;
		right.mu=(right.mu*root.mu)%t;
		left.sum=(left.sum*root.mu+(left.r-left.l+1)*root.add)%t;
		right.sum=(right.sum*root.mu+(right.r-right.l+1)*root.add)%t;	
		root.add=0;
		root.mu=1;
	}
}
void build(ll u,ll l,ll r)
{
	tr[u].l=l;
	tr[u].r=r;
	tr[u].sum=0;
	tr[u].mu=1;
	tr[u].add=0;
	if(l==r) 
	{
		tr[u].sum=a[l];
		return;
	}
	ll mid=l+r>>1;
	build(u<<1,l,mid);
	build(u<<1|1,mid+1,r);
	pushup(u);
	
}
void modify(ll u,ll l,ll r,int add)
{
    if(tr[u].l>=l && tr[u].r<=r)
    {
    	tr[u].add=(tr[u].add+add)%t;
    	tr[u].sum=(add*(tr[u].r-tr[u].l+1)+tr[u].sum)%t;	
		return;
	}
	
	pushdown(u);
	ll mid=tr[u].l+tr[u].r>>1;
	if(l<=mid) modify(u<<1,l,r,add);
	if(r>mid) modify(u<<1|1,l,r,add);
	pushup(u);
}
void modify1(ll u,ll l,ll r,ll mu)
{
	if(tr[u].l>=l && tr[u].r<=r)
	{
		tr[u].sum=(tr[u].sum*mu)%t;
		tr[u].add=(tr[u].add*mu)%t;
		tr[u].mu=(tr[u].mu*mu)%t;
		return;
	}
	pushdown(u);
	ll mid=tr[u].l+tr[u].r>>1;
	if(l<=mid) modify1(u<<1,l,r,mu);
		if(r>mid) modify1(u<<1|1,l,r,mu);
		pushup(u);
}
ll query(ll u,ll l,ll r)
{
	if(tr[u].l>=l && tr[u].r<=r)
	{
		return tr[u].sum%t;
	}
	pushdown(u);
	ll mid=tr[u].l+tr[u].r>>1;
	ll sum=0;
	if(l<=mid) sum+=query(u<<1,l,r);
	if(r>mid) sum+=query(u<<1|1,l,r);
	return sum%t;
	
}
int main()
{
    
	cin>>n>>m>>t;
	for(ll i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	build(1,1,n);
	while(m--)
	{
		ll op;
		ll b,c,d,e;
        scanf("%lld",&op);
        if(op==2)
        {
        	scanf("%lld %lld %lld",&b,&c,&d);
			modify(1,b,c,d);
		}
		else if(op==1)
		{
			scanf("%lld %lld %lld",&b,&c,&d);
			modify1(1,b,c,d);
		}
		else
		{
			scanf("%lld %lld",&b,&c);
			printf("%lld\n",query(1,b,c)%t);
		}
        
	}
	return 0;
}
